<template>
  <div class="app-container">
    <el-form label-width="100px" width="200">
        <el-form-item label="仓库名称">
            <el-input v-model="warehouse.warehouseName"/>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="saveWareInfo()">保存</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>

<script>
import ware from '@/api/ware';
export default {
    name:'WarehouseSave',
    data(){
        return {
            warehouse:{
                warehouseName:''
            }
        }
    },
    methods:{
        saveWareInfo(){
            let wareDto = {
                warehouseName:this.warehouse.warehouseName
            }
            console.log('待添加的数据wareDto：', wareDto)
            ware.saveWare(wareDto).then(
                response => {
                    console.log('仓库添加响应数据：', response)
                    let resData = response.data.data
                    let resCode = response.data.code
                    let resMsg = response.data.message
                    if(resCode == '200' && resData){
                        //提示
                        this.$message({
                            type: 'success',
                            message: '添加成功!'
                        })
                        //跳转列表页面，使用路由跳转方式实现
                        this.$router.push({path:'/ware_list'})
                    } else {
                        //异常提示
                        this.$message({
                            type: 'error',
                            message: resMsg
                        })
                    }
                },
                error => {
                    console.error('仓库添加异常信息：', error)
                }
            )
        }
    }
}
</script>

<style scoped>
  .el-input{
    width: 223px;
  }
</style>